<template>
  <div
    class="vue-dropdown default-theme"
    @mouseleave="mouseIn = false"
    @mouseenter="mouseIn = true"
  >
    <div class="search-icon">
      <input
        ref="searchText"
        type="text"
        class="search-text"
        v-on:focus="isShow = true"
        v-on:blur="close"
        placeholder="请输入关键字"
        v-model="community"
      />
      <img class="down-icon" @click="isShow = true" src="@/assets/arrow-down.png" />
    </div>
    <div class="list-and-search" v-show="isShow">
      <div
        v-for="item in datalist"
        v-show="item[3].includes(community)"
        :key="item[0]"
        @click="itemClick(item[3])"
        class="list-item"
      >{{ item[3] }}</div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      datalist: [],
      isShow: false,
      community: "",
      mouseIn: false
    }
  },
  created () {
    this.getList()
  },
  methods: {
    getList () {
      let that = this
      this.$service.mock.community({}).then(res => {
        that.datalist = res
      })
    },
    itemClick (txt) {
      this.community = txt
      document.querySelector(".wrapper__bg").contentWindow.postMessage({ jd: "", xq: txt }, "*")
      this.isShow = false
    },
    close () {
      if (!this.mouseIn)
        this.isShow = false
    }
  },
}
</script>

<style lang="scss" scoped>
.vue-dropdown.default-theme {
  width: $base * 360px;
  height: $base * 50px;
  border: 2px solid #07368b;
  /* display: flex; */
  /* justify-content: center; */
  /* align-items: center; */
  position: absolute;
  right: $base * 10px;
  top: $base * 113px;
  background: rgba(7, 54, 139, 0.8);
  /* cursor: pointer; */
  pointer-events: auto;
  /* justify-content: space-between; */

  .search-icon {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    justify-content: space-between;
  }

  .search-text {
    position: relative;
    margin-left: $base * 21px;
    height: $base * 22px;
    background: transparent;
    border: 0px;
    placeholder: '请输入关键字';
    font-size: $base * 16px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 0px;
    color: rgba(255, 255, 255, 1);
    opacity: 1;
    outline: none;
    width: 100%;
  }

  .down-icon {
    height: $base * 12px;
    width: $base * 24px;
    position: relative;
    margin-right: $base * 20px;
  }
}

.list-and-search {
  position: relative;
  background: RGBA(28, 52, 99, 0.8);
  border: 1px solid #ccc;
  max-height: $base * 300px;
  width: 100%;
  z-index: 99;
  overflow: scroll;

  /* opacity: 0.2; */
  /* display: none; */
  &.on {
    display: block;
  }

  .list-item {
    padding-left: $base * 21px;
    padding-right: $base * 21px;
    /* line-height: $base * 30px; */
    text-align: left;
    font-size: $base * 16px;
    color: #ffffff;
    height: $base * 44px;
    line-height: $base * 44px;
    font-size: $base * 16px;
    /* padding-left: $base * 14px; */
    font-family: PingFang SC;

    /* font-weight: 400; */
    &:hover {
      background-color: RGBA(19, 99, 104, 1);
    }
  }
}
</style>